<?php
function filter_text($str = '')
{
	$str	=	preg_replace('/<p>[\s]*&nbsp;[\s]*<\/p>/is','',$str);
    $str	=	strip_tags($str,'<a><b><h1><h2><h3><h4>');
    return $str;
}

function show_thumb($str,$thumb = '155-110')
{
	if($thumb == "")
	{
		$rs = site_url(preg_replace('/(thumb)_([0-9\-])+\//is','',$str));
	}
	else
	{
		$rs = site_url(preg_replace('/(thumb)_([0-9\-])+\//is','$1_'.$thumb.'/',$str));
	}
	return $rs;
}

function snippet($text, $length=140, $tail="...")
{
    $text = trim($text);
    $txtl = strlen($text);
    if($txtl > $length)
    {
        for($i=1;$text[$length-$i]!=" ";$i++)
        {
            if($i == $length)
            {
                return substr($text,0,$length) . $tail;
            }
        }
        $text = substr($text,0,$length-$i+1) . $tail;
    }
    return $text;
}

function timetostr($date)
{
	return strtotime($date);
}

function doi_cho($arr = array(),$value)
{
	$temp=array();
	if(!in_array($value,$arr)){
		$arr[]=$value;
		asort($arr);
		foreach($arr as $v){
			$temp[]=$v;
		}
	}
	else{
		$temp=$arr;
	}
	return $temp;
}

function tinh_src($x = 0)
{
        if($x <= 20000){
        	$y = 0;
        }
        elseif($x > 20000 && $x <= 30000){
        	$y = $Y1*0.035;
        }
        elseif($x > 30000 && $x <= 40000){
        	$y = (350) + ($x-30000)*0.055;
        }
        elseif($x > 40000 && $x <= 80000){
        	$y = (900) + ($x-40000)*0.085;
        }
        elseif($x > 80000 && $x <= 160000){
        	$y = (4300) + ($x-80000)*0.14;
        }
        elseif($x > 160000 && $x <= 320000){
        	$y = (15500) + ($x-160000)*0.17;
        }
        elseif($x > 320000){
        	$y = 42700+($x-320000)*0.2;
        }
        return $y;
}

